package lock2;

public class MyReetantLock2 {
	private boolean lock = false;
	private Thread lockBy = null;
	private int lockCount = 0;
	
	public synchronized void lock() {
		while(lock && lockBy != Thread.currentThread()) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		lockBy = Thread.currentThread();
		lockCount++;
		lock = true;
		System.out.println("lockCount:"+lockCount);
	}
	
	public synchronized void unLock() {
		if(lockBy == Thread.currentThread()) {
			lock = false;
			lockCount--;
			notifyAll();
			System.out.println("lockCount:"+lockCount);
		}
	}

}
